package cs2340.todolist.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import cs2340.todolist.model.ToDoItem;

public class TodoItemsView extends ScrollView {
	public static final ViewGroup.LayoutParams	LISTING_PARAMS = new ViewGroup.LayoutParams(
																			ViewGroup.LayoutParams.MATCH_PARENT,
																			ViewGroup.LayoutParams.WRAP_CONTENT);
	public static final TableRow.LayoutParams	ITEM_BUTTON_PARAMS = new TableRow.LayoutParams(
																    TableRow.LayoutParams.MATCH_PARENT,
																	TableRow.LayoutParams.WRAP_CONTENT,
																			1.0f);
	public static final TableLayout.LayoutParams  ROW_PARAMS =  new TableLayout.LayoutParams(
															    TableLayout.LayoutParams.MATCH_PARENT,
																TableLayout.LayoutParams.WRAP_CONTENT);
	
	
	private TableLayout itemsListing;
	
	/**
	 * contructor for this class
	 * @param context - context this will be used in
	 * @param attrs - attribute set for this
	 */
	public TodoItemsView(Context context, AttributeSet attrs) {
		super(context, attrs);
		itemsListing = new TableLayout(context);
		//itemsListing.setOrientation(LinearLayout.VERTICAL);
		setVerticalScrollBarEnabled(true);
		addView(itemsListing,LISTING_PARAMS);
	}
	
	/**
	 * adds a todoitem button to the view
	 * @param item - item to be added
	 */
	public void addToDoItemButton(ToDoItem item) {
		TableRow row = new TableRow(getContext());
		row.addView(new TodoItemButton(getContext(),null,item),ITEM_BUTTON_PARAMS);
		itemsListing.addView(row);
	}
}
